﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBACProject.Application.Permission.Dto;
using RBACProject.Application.Permission;
using System.Threading.Tasks;
using RBACProject.WebApi.Filter;

namespace RBACProject.WebApi.Controllers
{
    /// <summary>
    /// 权限分配 Api控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]//权限锁
    //[AuthorizationFilterAttribute]//自定义授权过滤器
    public class PermissionController : ControllerBase
    {
        /// <summary>
        /// 获取属性值
        /// </summary>
        private readonly IPermissionService Ipremisson;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ipremisson">参数</param>
        public PermissionController(IPermissionService ipremisson)
        {
            Ipremisson = ipremisson;
        }

        /// <summary>
        /// 反填（加载）角色权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMenuId(int id)
        {
            return Ok(await Ipremisson.GetMenuId(id));
        }

        /// <summary>
        /// 角色权限分配（修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> EditAssignPermission(PermissonDto dto) 
        {
            return Ok(await Ipremisson.EditAssignPermission(dto));
        }

       
    }
}
